/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package do_.com.pbd.business.referrals.creditcardreferralprogramstatusupdater;

import do_.com.bpd.hrtoolspersistence.configuration.ConfigManager;
import do_.com.pbd.business.referrals.creditcardreferralprogramstatusupdater.impl.NewFilesMonitor;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Singleton;
import javax.ejb.LocalBean;

/**
 *
 * @author Administrator
 */
@Singleton
@LocalBean
public class Installer {

    public static final String REPOSITORY_CONFIG_NAME = Installer.class.getPackage() + ".REPOSITORY_PATH";
    public static String CASES_REPOSITORY = "";
    public static final String MINIMUM_POLLING_RATE_CONFIG_NAME = Installer.class.getPackage() + ".MINIMUM_POLLING_RATE";
    public static int MINIMUM_POLLING_RATE = 0;
    public static String CURRENT_POLLING_RATE_CONFIG_NAME = Installer.class.getPackage() + ".CURRENT_POLLING_RATE";
    public static int CURRENT_POLLING_RATE = 0;
    public static String RUN_STATUS = "1";

    public Installer() {
        try {

            Thread.sleep(20000);
            System.out.println("Installing CreditCardReferralProgramStatusUpdater");
            ConfigManager cm = new ConfigManager();

            //<editor-fold defaultstate="collapsed" desc="Repository config">
            //cm.getConfig(RUN_STATUS, RUN_STATUS)

            Installer.CASES_REPOSITORY = cm.getConfig(Installer.REPOSITORY_CONFIG_NAME, System.getenv("TMP") + "\\repository", "Path to upload status files");
            File tem = new File(Installer.CASES_REPOSITORY);
            if (!tem.exists()) {
                System.out.println("Created dir:" + tem.mkdir());
            }

            Logger.getLogger(Installer.class.getName()).log(Level.INFO, "Repository directory set to: {0}", cm.getConfig(Installer.REPOSITORY_CONFIG_NAME));
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="Minimum polling config">
            Installer.MINIMUM_POLLING_RATE = Integer.parseInt(cm.getConfig(Installer.MINIMUM_POLLING_RATE_CONFIG_NAME, "30000", "Minimum rate allowed at which the new file poller will beat"));
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="Current polling rate">
            Installer.CURRENT_POLLING_RATE = Integer.parseInt(cm.getConfig(Installer.CURRENT_POLLING_RATE_CONFIG_NAME, String.valueOf(Installer.MINIMUM_POLLING_RATE), "Current rate at which the new file poller will beat"));
            //</editor-fold>

            //Here the thing starts
            NewFilesMonitor nfm = new NewFilesMonitor();
        } catch (Exception ex) {
            Logger.getLogger(Installer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
